import * as React from "react";
import Modal from "antd/es/modal/Modal";
import {Button, Card, Col, Form, Input, InputNumber, notification, Row} from "antd";
import {
    FieldNumberOutlined,
    IdcardOutlined, MailOutlined, SecurityScanOutlined,
    UnorderedListOutlined,
    UserOutlined,
    WhatsAppOutlined
} from "@ant-design/icons";
import {createKey} from "../../requests/KeyManageRequest";
import {createRole} from "../../requests/RoleManageRequest";
import {createUser} from "../../requests/UserManageRequest";
import {createBudget} from "../../requests/BudgetManageRequest";


export default  class CreateBudgetModal extends React.Component{

    constructor(props) {
        super(props);
        this.state = {
            isModalVisible: false,
            formRef: React.createRef(),
        };
        this.props.onRef(this)
    }

    showModal = () => {
        this.setState({
            isModalVisible: true
        })
    };

    handleCancel = () => {
        this.setState({
            isModalVisible: false
        })
    };

    handleOk = () => {
        this.state.formRef.current.validateFields()
            .then(values => {
                console.log("Begin to create budget with params:" + JSON.stringify(values))
                createBudget(values).then(edpKey => {
                    notification.info({message: "创建预算成功", description: "创建为用户" + edpKey.result.userName + "创建预算成功"});
                })
                this.setState({
                    isModalVisible: false
                })
            })
            .catch(info => {
                console.log('Validate message:', info);
            });
    };

    render = () => {
        return (
            <Modal title="创建预算" visible={this.state.isModalVisible} onOk={this.handleOk} onCancel={this.handleCancel}>
                <Form name="basic" ref={this.state.formRef}>
                    <Form.Item
                        label="用户账户" name="userName"
                        rules={[{required: true, message: '请输入用户账户！'}]}>
                        <Input prefix={<IdcardOutlined/>}/>
                    </Form.Item>

                    <Form.Item
                        label="预算总金额" name="totalAmount"
                        rules={[{required: true, message: '请输入预算总金额！'}]}>
                        <Input prefix={<UnorderedListOutlined/>}/>
                    </Form.Item>

                    <Form.Item
                        label="备注" name="remark" >
                        <Input prefix={<SecurityScanOutlined />}/>
                    </Form.Item>
                </Form>
            </Modal>
        );
    }
}

